home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-03-19 | 2.2 KB | 110 lines | [TEXT/MPS ] |
- //---------------------------------------------------------------------
- //
- // Copyright © 1992 David Peterson.
- // All rights reserved.
- //
- // Permission to use, copy, modify, and distribute this software for
- // any purpose and without fee is hereby granted, provided that the
- // above copyright notice appear in all copies and that both that
- // copyright notice and this permission notice appear in supporting
- // documentation.
- //
- //---------------------------------------------------------------------
-
- #include "TalkD.h"
-
- #include "U_ctl.h"
- #define VERSION "with old talk protocol (otalk)"
-
- #include <myUtils.h>
- #include <UDP.h>
- #include <DNR.h>
-
- #include <StdIO.h>
- #include <String.h>
- #include <Sysequ.h>
- #include <Memory.h>
- #include <Packages.h>
-
- void main();
-
- void
- main()
- {
- InitUDaemonApp(*((long*) DefltStack));
-
- TalkD* aDaemon = new TalkD;
- if (aDaemon) {
- aDaemon->Initialize();
- aDaemon->Run();
-
- delete aDaemon;
- }
- }
-
- void
- TalkD::InstallAEHandlers()
- {
- Inherited::InstallAEHandlers();
-
- OSErr theErr;
-
- theErr = AEInstallEventHandler('INET', 'USTR',
- (EventHandlerProcPtr) &AEStreamHandler, (long) this, false);
-
- if (theErr != noErr)
- ExitToShell();
- }
-
- pascal OSErr
- AEStreamHandler(AppleEvent* messagein, AppleEvent* /*reply*/, long refIn)
- {
- AEDesc streamDesc;
- OSErr theErr;
- StreamPtr stream;
-
- if ((theErr = AEGetParamDesc(messagein, 'STRM', typeLongInteger, &streamDesc)) == noErr) {
- HLock(streamDesc.dataHandle);
- stream = *((StreamPtr*) *streamDesc.dataHandle);
- HUnlock(streamDesc.dataHandle);
-
- theErr = AEDisposeDesc(&streamDesc);
- }
-
- if (theErr == noErr)
- ((TalkD*) refIn)->HandleNewStream(stream);
-
- return theErr;
- }
-
- void
- TalkD::HandleNewStream(StreamPtr stream)
- {
- CTL_MSG msg;
- short len;
- char remote[32];
- char string[255];
-
- unsigned long time;
- Str63 datestr;
- Str63 timestr;
-
- len = sizeof(msg);
- udpRead(stream, &msg, &len);
-
- GetDateTime(&time);
- IUDateString(time, shortDate, datestr);
- IUTimeString(time, false, timestr);
-
- dnrAddrToName(msg.ctl_addr.sin_addr.s_addr, remote, nil, nil);
-
- sprintf(string, "Talk Daemon @ %P, %P:\n\n%s at %s wants to talk to %s\n%s",
- timestr, datestr, msg.l_name, remote, msg.r_name, VERSION);
-
- this->PostNotification(string);
-
- udpRelease(stream);
-
- this->DoQuit();
- }
-